<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="机构" prop="departmentId">
        <el-select
          v-model="queryParams.departmentId"
          placeholder="请选择机构"
          filterable
          clearable
          @change="deptChange"
        >
          <el-option
            v-for="item in departmentList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="停车场" prop="parkId">
          <el-select v-model="queryParams.parkId" placeholder="请选择" clearable >
            <el-option
              v-for="item in allParkList"
              :key="item.id"
              :label="item.name"
              :value="item.id"/>
          </el-select>
        </el-form-item>
      <el-form-item label="泊位编码" prop="berthCode">
        <el-input
          v-model="queryParams.berthCode"
          placeholder="请输入泊位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="取证工单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择取证工单状态" clearable>
          <el-option
            v-for="item in dict.type.EEvidenceSheetStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange"
          type="datetimerange"
          range-separator="-"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          :default-time="['00:00:00','23:59:59']">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="spparkplaceList" >
      <el-table-column 
      v-for="(item,index) in tableList"
      :key="index"
      :label="item.label" align="center" :prop="item.prop" :width="item.width ? item.width : ''">
        <template 
        slot-scope="{row}">
          <dict-tag v-if="item.prop == 'status'" :options="dict.type.EEvidenceSheetStatus" :value="row[item.prop]"/>
          <div v-else>{{row[item.prop]}}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="{row}">
          <div>
            <el-button
              size="mini"
              icon="el-icon-view"
              @click="handleUpdate(row)"
              type="text"
            >详情
            </el-button>
            
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

     <!-- 停车详情弹框 -->
     <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="30%" append-to-body>
      <div class="diy-mx-10" >
        <el-form
          ref="form"
          :model="form"
          label-width="110px"
        >
        <div>
          <div class="gdDetail_title">基础信息</div>
            <div style="line-height: 35px;margin: 10px 0;">
              <div class="gdDetail_item">
                <div class="item_dian"></div>
                <div class="item_text">机构名称：{{form.departmentName || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian"></div>
                <div class="item_text">片区名称：{{form.parkLotName || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian"></div>
                <div class="item_text">泊位编码：{{form.berthCode || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian"></div>
                <div class="item_text">
                  <div style="display: flex;align-items: center;">
                    取证工单状态：
                    <dict-tag :options="dict.type.EEvidenceSheetStatus" :value="form.status"/>
                  </div>
                </div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian"></div>
                <div class="item_text">开始时间：{{form.startTime || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian item_dian1"></div>
                <div class="item_text">派单时间：{{form.dispatchTime || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian item_dian1"></div>
                <div class="item_text">结束时间：{{form.endTime || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian item_dian1"></div>
                <div class="item_text">处理者：{{form.processBy || ''}}</div>
              </div>
            </div>
            <div class="gdDetail_title">详细信息</div>
            <div style="line-height: 35px;margin: 10px 0;">
            <div class="gdDetail_item" v-if="form.plateNumber">
                <div class="item_dian"></div>
                <div class="item_text">车牌号码：{{form.plateNumber || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian"></div>
                <div class="item_text">入场时间：{{form.enterTime || ''}}</div>
              </div>
              <div class="gdDetail_item">
                <div class="item_dian item_dian1"></div>
                <div class="item_text">出场时间：{{form.outTime || ''}}</div>
              </div>
            </div>
          </div>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {fetchList,getDvidenceSheet} from "@/api/lcPark/certificatWorkOrder";
import { getDepartmentList,getListAuthPark } from '@/api/base'
import { timesToYyMmDd1,YyMmDdToTimes,getEndStartTime } from "@/utils/time.js";
export default {
  name: "certificatWorkOrder",
  dicts: ['EEvidenceSheetStatus',],
  components:{},
  data() {
    return {
      // 表单参数
      form: {},
      // 是否显示弹出层
      open: false,
      title:"",
      tableList:[
        {label:'机构名称',prop:'departmentName',},
        {label:'片区名称',prop:'parkLotName',},
        {label:'泊位编码',prop:'berthCode',},
        {label:'取证工单状态',prop:'status',},
        {label:'开始时间',prop:'startTime',},
        {label:'派单时间',prop:'dispatchTime',},
        {label:'结束时间',prop:'endTime',},
        {label:'处理者',prop:'processBy',},
      ],//表格字段显示
      //片区数据
      areaList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车位信息表格数据
      spparkplaceList: [],
      // 查询参数
      queryParams: {
        page: 1,
        pageSize: 10,
        dateRange:[],
      },
      departmentList: [],//机构数据
      allParkList: [],//停车场数据
    };
  },
  created() {
    this.getDepartmentList();
    this.getTimeData();
  },
  methods: {
    /** 详情按钮操作 */
    handleUpdate(row) {
      const pkParkrecordId = row.id;
      getDvidenceSheet(pkParkrecordId).then(response => {
        let data = response.data || {}
        this.form = data;
        this.open = true;
        this.title = "取证工单详情";
      });
    },
    getTimeData() {
      let starTimes = timesToYyMmDd1(new Date(),'YY-MM-DD')
      let end = YyMmDdToTimes(timesToYyMmDd1(new Date())) + 24 * 60 * 60 * 1000
      let endTime1 = timesToYyMmDd1(end,'YY-MM-DD')
      let getEndStartTimes = getEndStartTime([starTimes,starTimes])
      let getEndStartTimes1 = getEndStartTime([endTime1,endTime1])
      let starTime = getEndStartTimes.startTime
      let endTime = getEndStartTimes1.startTime
      console.log([
        starTime,
        endTime,
      ])
      this.queryParams.dateRange = [
        starTime,
        endTime,
      ]
      this.getList();
      // timesData(query).then(response => {
      //   if (response.code != 200) return;
      //   this.queryParams.dateRange = response.data;
      //   this.getList();
      // });
    },
    async deptChange(e){//机构下拉选择
      let queryParams = {...this.queryParams}
      queryParams.parkId = ''
      this.queryParams = {...queryParams}
      if(!e) return this.allParkList = []
      this.allParkList = await this.getListAuthPark(e)
    },
    getDepartmentList(){//获取机构
      getDepartmentList().then(res => {
        this.departmentList = res.data || []
      })
    },
    async getListAuthPark(departmentId){//获取停车场
      let res = await getListAuthPark({departmentId,parkType:2})
      return res.data || []
    },
    /** 查询车位信息列表 */
    getList() {

      this.loading = true;
      if (!this.queryParams.dateRange) this.queryParams.dateRange = [];
      let queryParams = {
        ...this.queryParams
      }
      if(queryParams.dateRange.length) {
        queryParams.startTime = queryParams.dateRange[0]
        queryParams.endTime = queryParams.dateRange[1]
      }
      delete queryParams.dateRange
      fetchList(queryParams).then(response => {
        let data = response.data || {}
        let rows = data.list || []
        this.spparkplaceList = rows
        this.total = data.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.dateRange = []
      this.handleQuery();
    },
  }
};
</script>
<style lang="scss">
.gdDetail_title{
  background-color: #4BA2FE;
  width: 100px;height: 30px;border-radius: 5px;
  color: #fff;display: flex;align-items: center;justify-content: center;

}
.gdDetail_item{
  display: flex;align-items: center;
}
.item_dian{
  width: 8px;height: 8px;border-radius: 50%;background-color: #ED9C12;margin-right: 10px;
}
.item_dian1{background-color: #4AA4F6;}
.item_text{
  overflow: hidden; //超出的文本隐藏
  text-overflow: ellipsis; //溢出用省略号显示
  white-space: nowrap;  // 默认不换行；
  flex: 1;display: block;}

</style>
